import java.util.*;

/**
 * @Author 12629
 * @Description：
 */
public class Test {

    public static void calcWordNum(String[] words) {

        Map<String ,Integer> map = new HashMap<>();

        for(String word : words) {
            //if(map.get(word) != null) {
            if(map.containsKey(word)) {
                int oldNum = map.get(word);
                map.put(word,oldNum+1);
            }else {
                map.put(word,1);
            }
        }
        //遍历map
        for(Map.Entry<String ,Integer> entry :map.entrySet()) {
            System.out.println("单词 "+entry.getKey()+" 出现了 "+entry.getValue()+"次！");
        }
    }

    public static void main(String[] args) {
        String[] words = {"this","is","good","man","this","good","good"};
        calcWordNum(words);
    }

    public static void main5(String[] args) {
        //把10W个数据 去重
        int[] array = {1,2,3,4,5,6,3,2,1};
        Set<Integer> set = new HashSet<>();
        for(int i = 0;i < array.length;i++) {
            set.add(array[i]);
        }
        System.out.println(set);
    }

    public static void main4(String[] args) {
        //找到10W个数据当中  第一个重复的数据
        int[] array = {1,2,3,4,5,6,3,2,1};
        Set<Integer> set = new HashSet<>();

        for(int i = 0;i < array.length;i++) {
            if(!set.contains(array[i])) {
                set.add(array[i]);
            }else {
                System.out.println(array[i]);
                return;
            }
        }
    }

    public static void main3(String[] args) {
        Map<String,Integer> map = new HashMap<>();
        map.put("hello",3);

        Set<String> set = new HashSet<>();

        set.add("abc");
    }

    public static void main2(String[] args) {
        Person person1 = new Person("1234");
        Person person2 = new Person("1234");

        System.out.println(person1.hashCode());
        System.out.println(person2.hashCode());
    }

    public static void main1(String[] args) {
        HashBuck hashBuck = new HashBuck();
        hashBuck.put(1,110);
        hashBuck.put(2,220);
        hashBuck.put(3,330);
        hashBuck.put(4,440);
        hashBuck.put(14,1440);
        hashBuck.put(24,2440);
        hashBuck.put(7,770);
        hashBuck.put(8,880);

        System.out.println(hashBuck.get(145));
    }
}
